package tree;

/**
 * @Author wangtengyu
 * @Create 2018-09-12-10:00 输入一个二叉树，返回一个二叉树的镜像
 *
 *
 *
 * 从根节点开始 如果当前节点为null，就return 不为null的话，当前节点的左子树和右子树互换
 */
public class treeImage {


  public void getTreeImage(TreeNode root) {

    if (root == null) {
      return;
    }

    TreeNode temp = root.getLeft();
    root.setLeft(root.getRight());
    root.setRight(temp);

    getTreeImage(root.getLeft());
    getTreeImage(root.getRight());
  }

  public static void main(String[] args) {
    SimpleTreeCreator creator = new SimpleTreeCreator();
    TreeIterator iterator = new TreeIterator();
    treeImage treeImage = new treeImage();
    TreeNode treeNode = creator.createSampleTree();
    System.out.println("原先二叉树的先序遍历结果");
    iterator.preOrder(treeNode);
    System.out.println();
    System.out.println("二叉树镜像的先序遍历结果");
    treeImage.getTreeImage(treeNode);
    iterator.preOrder(treeNode);
  }

}
